<template>
  <div class="param-main">
    <el-form ref="tblMain" :model="tblMain" labelPosition="right" inline="" label-suffix=":" label-width="100px">
      <el-row :span="24">
        <el-col :span="6">
          <el-form-item label="商品名称">
            <el-input v-model="tblMain.param.name" size="small" placeholder=""></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <div class="page-pane2">
        <el-button type="primary" size="small" @click="initTableData()">查询</el-button>
        <el-button size="small" @click="dataReset()">清空</el-button>
      </div>
    </el-form>
    <div>
      <el-table ref="tblMain" style="margin-top: 10px;" :data="tblMain.items" @selection-change="handleSelectionChange"
        v-loading.body="tblMain.loading" border stripe>
        <el-table-column type="index" width="80" label="序号" align="center"></el-table-column>
        <el-table-column label="操作" align="center" width="160px">
          <template slot-scope="scope">
            <el-button type="text" @click="handleEdit(scope.row)">结算详情</el-button>
          </template>
        </el-table-column>
        <el-table-column prop="name" label="结算名称" align="center" show-overflow-tooltip></el-table-column>
        <el-table-column prop="storeSettlementDate" label="结算周期" align="center" show-overflow-tooltip></el-table-column>
        <el-table-column prop="totalAmount" label="结算总金额" align="center" show-overflow-tooltip></el-table-column>
        <el-table-column prop="settlementTime" label="结算数据生成时间" align="center" show-overflow-tooltip></el-table-column>
      </el-table>
      <el-pagination style="margin-top: 10px" :current-page.sync="tblMain.currentPage" :page-size="tblMain.pageSize"
        :total="tblMain.total" layout="total, sizes, prev, pager, next" @size-change="handleSizeChange"
        @current-change="handleCurrentChange"></el-pagination>
    </div>
    <store-settlement-dialog ref="modalForm"></store-settlement-dialog>
  </div>
</template>
<script>
import StoreSettlementDialog from './components/StoreSettlementDialog'
import tool from '@/tool'
import {
  storeSettlementInfo,
  storeSettlementInfoDetail
} from '@/api/businessExtend'
export default ({
  name: 'StoreSettlementList',
  components: {
    StoreSettlementDialog
  },
  data () {
    return {
      tblMain: tool.genTableData({
        param: {
          name: '',
        },
        items: []
      }),
    }
  },
  mounted () {
    this.initTableData();
  },
  methods: {
    handleEdit (val) {
      this.$refs.modalForm.edit(val);
    },
    // 单个删除
    async deleteRow (val) {
      this.$confirm('确认收货?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async () => {
        let params = []
        params.push(val.id)
        await this.deleteTblMain(params)
      }).catch(() => {
      })
    },
    // 删除数据
    deleteTblMain (params) {
      let me = this
      me.tblMain.loading = true
      storeOrderConfirm({ ids: params }).then(res => {
        me.tblMain.loading = false
        let data = res.data
        if (data && data.code == 0) {
          me.$message.success('操作成功')
          this.initTableData()
        }
      }).catch(() => {
        me.$message.error('请求失败')
        me.tblMain.loading = false
      })
    },
    dataReset () {
      this.tblMain.currentPage = 1
      this.tblMain.pageSize = 10
      this.tblMain.param.name = ''
      this.initTableData()
    },
    handleSelectionChange (val) {
      this.tblMain.selection = val;
    },
    handleSizeChange (val) {
      this.tblMain.pageSize = val
      this.initTableData()
    },
    handleCurrentChange (val) {
      this.tblMain.currentPage = val
      this.initTableData()
    },
    initTableData () {
      let me = this
      me.tblMain.selection = []
      let param = {
        name: me.tblMain.param.name,
        page: me.tblMain.currentPage,
        size: me.tblMain.pageSize
      }
      me.tblMain.loading = true
      storeSettlementInfo(param).then(res => {
        me.tblMain.loading = false
        let data = res.data
        if (data && data.code == 0) {
          me.tblMain.items = data.data.records
          me.tblMain.total = data.data.total
        }
      })
    },
  }
})
</script>
